$(function(){
	$("#toRegister").click(function(){
		window.location.href = window.url.REGISTER;
		return false;
	});
	
	$("#loginSubmit").click(function(){
		
		var flag = $("#loginForm").valid();
		if(!flag)
			return false;
		var formParams = $("#loginForm").serialize();
		var url = window.url.LOGIN;
		$.post(url,formParams,function(result){
			if(result.code==0) {
				layer.msg("登录成功",{icon:1,time:700},function(){
					layer_close();
				})
			}else if(result.code==1) {
				layer.alert(result.message,{icon:2});
				$("#captcha").click();
			}
		})
	})
	function layer_close(){
		var winName = window.name;
		if(winName == "") {
			window.location.href = url.MAIN;
			return;
		}
		var index = parent.layer.getFrameIndex(winName);
		parent.layer.close(index);
	}
})